/*
 * Copyright 2007 Matt Jensen
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */
package org.jtell;

import org.jtell.internal.EventChannelInternal;

import java.util.Set;

/**
 * <p>
 * <code>EventSinkRegistry</code> defines the public interface to an event registry. An event registry maintains information
 * on all registered event sinks. It allows for the addition, removal, and retrieval of event sinks. 
 * </p>
 */
public interface EventSinkRegistry
{
    /**
     * <p>
     * Get all event sinks which have been associated with given event and source classes and/or their superclasses.
     * </p>
     * 
     * @param channel the event channel.
     * @param eventMetadata the event metadata.
     * @return {@link Set} of {@link EventSink} instances.
     */
    Set<EventSink> findEventSinks(EventChannelInternal channel, EventMetadata eventMetadata);

    /**
     * <p>
     * Register an event sink for a given event channel.
     * </p>
     *
     * @param channel the channel for which the event sink is to be registered.
     * @param eventSink the event sink to register.
     */
    void registerEventSink(EventChannelInternal channel, EventSink eventSink);

    /**
     * <p>
     * Unregister all event sinks for a given event channel.
     * </p>
     *
     * @param channel the channel for which all event sinks are to be unregistered.
     */
    void unregisterAllEventSinks(EventChannelInternal channel);

    /**
     * <p>
     * Unregister all event sinks for a given event channel which are owned by a given object. The owner of an event
     * sink is obtained via {@link EventSink#getOwner()}, and {@link Object#equals(Object)} is used to check for
     * matches. 
     * </p>
     *
     * @param channel the channel for which event sinks are to be unregistered.
     * @param owner the owner object whose event sinks are to be unregistered.
     */
    void unregisterEventSinksForOwner(EventChannelInternal channel, Object owner);
}
